(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^3).


The TRS R consists of the following rules:

app(nil, y) → y
app(add(n, x), y) → add(n, app(x, y))
reverse(nil) → nil
reverse(add(n, x)) → app(reverse(x), add(n, nil))
shuffle(nil) → nil
shuffle(add(n, x)) → add(n, shuffle(reverse(x)))

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^3).


The TRS R consists of the following rules:

app(nil, y) → y [1]
app(add(n, x), y) → add(n, app(x, y)) [1]
reverse(nil) → nil [1]
reverse(add(n, x)) → app(reverse(x), add(n, nil)) [1]
shuffle(nil) → nil [1]
shuffle(add(n, x)) → add(n, shuffle(reverse(x))) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

app(nil, y) → y [1]
app(add(n, x), y) → add(n, app(x, y)) [1]
reverse(nil) → nil [1]
reverse(add(n, x)) → app(reverse(x), add(n, nil)) [1]
shuffle(nil) → nil [1]
shuffle(add(n, x)) → add(n, shuffle(reverse(x))) [1]

The TRS has the following type information:
app :: nil:add → nil:add → nil:add
nil :: nil:add
add :: a → nil:add → nil:add
reverse :: nil:add → nil:add
shuffle :: nil:add → nil:add

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants:

const

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

app(nil, y) → y [1]
app(add(n, x), y) → add(n, app(x, y)) [1]
reverse(nil) → nil [1]
reverse(add(n, x)) → app(reverse(x), add(n, nil)) [1]
shuffle(nil) → nil [1]
shuffle(add(n, x)) → add(n, shuffle(reverse(x))) [1]

The TRS has the following type information:
app :: nil:add → nil:add → nil:add
nil :: nil:add
add :: a → nil:add → nil:add
reverse :: nil:add → nil:add
shuffle :: nil:add → nil:add
const :: a

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

nil => 0
const => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

app(z, z') -{ 1 }→ y :|: y >= 0, z = 0, z' = y
app(z, z') -{ 1 }→ 1 + n + app(x, y) :|: n >= 0, x >= 0, y >= 0, z = 1 + n + x, z' = y
reverse(z) -{ 1 }→ app(reverse(x), 1 + n + 0) :|: n >= 0, x >= 0, z = 1 + n + x
reverse(z) -{ 1 }→ 0 :|: z = 0
shuffle(z) -{ 1 }→ 0 :|: z = 0
shuffle(z) -{ 1 }→ 1 + n + shuffle(reverse(x)) :|: n >= 0, x >= 0, z = 1 + n + x

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1),0,[app(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1),0,[reverse(V, Out)],[V >= 0]).
eq(start(V, V1),0,[shuffle(V, Out)],[V >= 0]).
eq(app(V, V1, Out),1,[],[Out = V2,V2 >= 0,V = 0,V1 = V2]).
eq(app(V, V1, Out),1,[app(V4, V5, Ret1)],[Out = 1 + Ret1 + V3,V3 >= 0,V4 >= 0,V5 >= 0,V = 1 + V3 + V4,V1 = V5]).
eq(reverse(V, Out),1,[],[Out = 0,V = 0]).
eq(reverse(V, Out),1,[reverse(V6, Ret0),app(Ret0, 1 + V7 + 0, Ret)],[Out = Ret,V7 >= 0,V6 >= 0,V = 1 + V6 + V7]).
eq(shuffle(V, Out),1,[],[Out = 0,V = 0]).
eq(shuffle(V, Out),1,[reverse(V9, Ret10),shuffle(Ret10, Ret11)],[Out = 1 + Ret11 + V8,V8 >= 0,V9 >= 0,V = 1 + V8 + V9]).
input_output_vars(app(V,V1,Out),[V,V1],[Out]).
input_output_vars(reverse(V,Out),[V],[Out]).
input_output_vars(shuffle(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [app/3]
1. recursive [non_tail] : [reverse/2]
2. recursive : [shuffle/2]
3. non_recursive : [start/2]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into app/3
1. SCC is partially evaluated into reverse/2
2. SCC is partially evaluated into shuffle/2
3. SCC is partially evaluated into start/2

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations app/3
* CE 6 is refined into CE [11]
* CE 5 is refined into CE [12]


### Cost equations --> "Loop" of app/3
* CEs [12] --> Loop 8
* CEs [11] --> Loop 9

### Ranking functions of CR app(V,V1,Out)
* RF of phase [9]: [V]

#### Partial ranking functions of CR app(V,V1,Out)
* Partial RF of phase [9]:
- RF of loop [9:1]:
V


### Specialization of cost equations reverse/2
* CE 8 is refined into CE [13,14]
* CE 7 is refined into CE [15]


### Cost equations --> "Loop" of reverse/2
* CEs [15] --> Loop 10
* CEs [14] --> Loop 11
* CEs [13] --> Loop 12

### Ranking functions of CR reverse(V,Out)
* RF of phase [11]: [V]

#### Partial ranking functions of CR reverse(V,Out)
* Partial RF of phase [11]:
- RF of loop [11:1]:
V


### Specialization of cost equations shuffle/2
* CE 10 is refined into CE [16,17]
* CE 9 is refined into CE [18]


### Cost equations --> "Loop" of shuffle/2
* CEs [18] --> Loop 13
* CEs [17] --> Loop 14
* CEs [16] --> Loop 15

### Ranking functions of CR shuffle(V,Out)
* RF of phase [14]: [V-1]

#### Partial ranking functions of CR shuffle(V,Out)
* Partial RF of phase [14]:
- RF of loop [14:1]:
V-1


### Specialization of cost equations start/2
* CE 2 is refined into CE [19,20]
* CE 3 is refined into CE [21,22]
* CE 4 is refined into CE [23,24]


### Cost equations --> "Loop" of start/2
* CEs [20,22,24] --> Loop 16
* CEs [19,21,23] --> Loop 17

### Ranking functions of CR start(V,V1)

#### Partial ranking functions of CR start(V,V1)


Computing Bounds
=====================================

#### Cost of chains of app(V,V1,Out):
* Chain [[9],8]: 1*it(9)+1
Such that:it(9) =< -V1+Out

with precondition: [V+V1=Out,V>=1,V1>=0]

* Chain [8]: 1
with precondition: [V=0,V1=Out,V1>=0]


#### Cost of chains of reverse(V,Out):
* Chain [[11],12,10]: 2*it(11)+1*s(3)+3
Such that:aux(3) =< Out
it(11) =< aux(3)
s(3) =< it(11)*aux(3)

with precondition: [Out=V,Out>=2]

* Chain [12,10]: 3
with precondition: [V=Out,V>=1]

* Chain [10]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of shuffle(V,Out):
* Chain [[14],15,13]: 4*it(14)+2*s(13)+1*s(14)+3
Such that:aux(6) =< Out
it(14) =< aux(6)
aux(4) =< aux(6)
s(15) =< it(14)*aux(4)
s(13) =< s(15)
s(14) =< s(13)*aux(6)

with precondition: [V=Out,V>=2]

* Chain [15,13]: 3
with precondition: [V=Out,V>=1]

* Chain [13]: 1
with precondition: [V=0,Out=0]


#### Cost of chains of start(V,V1):
* Chain [17]: 1
with precondition: [V=0]

* Chain [16]: 7*s(22)+1*s(25)+2*s(30)+1*s(31)+3
Such that:aux(7) =< V
s(22) =< aux(7)
s(25) =< s(22)*aux(7)
s(28) =< aux(7)
s(29) =< s(22)*s(28)
s(30) =< s(29)
s(31) =< s(30)*aux(7)

with precondition: [V>=1]


Closed-form bounds of start(V,V1):
-------------------------------------
* Chain [17] with precondition: [V=0]
- Upper bound: 1
- Complexity: constant
* Chain [16] with precondition: [V>=1]
- Upper bound: 7*V+3+3*V*V+V*V*V
- Complexity: n^3

### Maximum cost of start(V,V1): 7*V+2+3*V*V+V*V*V+1
Asymptotic class: n^3
* Total analysis performed in 140 ms.

(10) BOUNDS(1, n^3)